home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 320 / compsrc2 / flow.c next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  61.0 KB  |  1,977 lines

  1. /* Data flow analysis for GNU compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. /* This file contains the data flow analysis pass of the compiler.
  23.    It computes data flow information
  24.    which tells combine_instructions which insns to consider combining
  25.    and controls register allocation.
  26.  
  27.    Additional data flow information that is too bulky to record
  28.    is generated during the analysis, and is used at that time to
  29.    create autoincrement and autodecrement addressing.
  30.  
  31.    The first step is dividing the function into basic blocks.
  32.    find_basic_blocks does this.  Then life_analysis determines
  33.    where each register is live and where it is dead.
  34.  
  35.    ** find_basic_blocks **
  36.  
  37.    find_basic_blocks divides the current function's rtl
  38.    into basic blocks.  It records the beginnings and ends of the
  39.    basic blocks in the vectors basic_block_head and basic_block_end,
  40.    and the number of blocks in n_basic_blocks.
  41.  
  42.    find_basic_blocks also finds any unreachable loops
  43.    and deletes them.
  44.  
  45.    ** life_analysis **
  46.  
  47.    life_analysis is called immediately after find_basic_blocks.
  48.    It uses the basic block information to determine where each
  49.    hard or pseudo register is live.
  50.  
  51.    ** live-register info **
  52.  
  53.    The information about where each register is live is in two parts:
  54.    the REG_NOTES of insns, and the vector basic_block_live_at_start.
  55.  
  56.    basic_block_live_at_start has an element for each basic block,
  57.    and the element is a bit-vector with a bit for each hard or pseudo
  58.    register.  The bit is 1 if the register is live at the beginning
  59.    of the basic block.
  60.  
  61.    To each insn's REG_NOTES is added an element for each register
  62.    that is live before the insn or set by the insn, but is dead
  63.    after the insn.
  64.  
  65.    To determine which registers are live after any insn, one can
  66.    start from the beginning of the basic block and scan insns, noting
  67.    which registers are set by each insn and which die there.
  68.  
  69.    ** Other actions of life_analysis **
  70.  
  71.    life_analysis sets up the LOG_LINKS fields of insns because the
  72.    information needed to do so is readily available.
  73.  
  74.    life_analysis deletes insns whose only effect is to store a value
  75.    that is never used.
  76.  
  77.    life_analysis notices cases where a reference to a register as
  78.    a memory address can be combined with a preceding or following
  79.    incrementation or decrementation of the register.  The separate
  80.    instruction to increment or decrement is deleted and the address
  81.    is changed to a POST_INC or similar rtx.
  82.  
  83.    Each time an incrementing or decrementing address is created,
  84.    a REG_INC element is added to the insn's REG_NOTES list.
  85.  
  86.    life_analysis fills in certain vectors containing information about
  87.    register usage: reg_n_refs, reg_n_deaths, reg_n_sets,
  88.    reg_live_length, reg_crosses_call and reg_basic_block.  */
  89.  
  90. #include <stdio.h>
  91. #include "config.h"
  92. #include "rtl.h"
  93. #include "basic-block.h"
  94. #include "regs.h"
  95. #include "hard-reg-set.h"
  96. #include "flags.h"
  97.  
  98. /* Get the basic block number of an insn.
  99.    This info should not be expected to remain available
  100.    after the end of life_analysis.  */
  101.  
  102. #define BLOCK_NUM(INSN)  uid_block_number[INSN_UID (INSN)]
  103.  
  104. /* This is where the BLOCK_NUM values are really stored.
  105.    This is set up by find_basic_blocks and used there and in life_analysis,
  106.    and then freed.  */
  107.  
  108. static short *uid_block_number;
  109.  
  110. /* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile.  */
  111.  
  112. #define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)]
  113. static char *uid_volatile;
  114.  
  115. /* Number of basic blocks in the current function.  */
  116.  
  117. int n_basic_blocks;
  118.  
  119. /* Maximum register number used in this function, plus one.  */
  120.  
  121. int max_regno;
  122.  
  123. /* Indexed by n, gives number of basic block that  (REG n) is used in.
  124.    Or gives -2 if (REG n) is used in more than one basic block.
  125.    Or -1 if it has not yet been seen so no basic block is known.
  126.    This information remains valid for the rest of the compilation
  127.    of the current function; it is used to control register allocation.  */
  128.  
  129. #define REG_BLOCK_UNKNOWN -1
  130. #define REG_BLOCK_GLOBAL -2
  131. short *reg_basic_block;
  132.  
  133. /* Indexed by n, gives number of times (REG n) is used or set, each
  134.    weighted by its loop-depth.
  135.    This information remains valid for the rest of the compilation
  136.    of the current function; it is used to control register allocation.  */
  137.  
  138. short *reg_n_refs;
  139.  
  140. /* Indexed by n, gives number of times (REG n) is set.
  141.    This information remains valid for the rest of the compilation
  142.    of the current function; it is used to control register allocation.  */
  143.  
  144. short *reg_n_sets;
  145.  
  146. /* Indexed by N, gives number of places register N dies.
  147.    This information remains valid for the rest of the compilation
  148.    of the current function; it is used to control register allocation.  */
  149.  
  150. short *reg_n_deaths;
  151.  
  152. /* Indexed by N, gives 1 if that reg is live across any CALL_INSNs.
  153.    This information remains valid for the rest of the compilation
  154.    of the current function; it is used to control register allocation.  */
  155.  
  156. char *reg_crosses_call;
  157.  
  158. /* Total number of instructions at which (REG n) is live.
  159.    The larger this is, the less priority (REG n) gets for
  160.    allocation in a real register.
  161.    This information remains valid for the rest of the compilation
  162.    of the current function; it is used to control register allocation.
  163.  
  164.    local-alloc.c may alter this number to change the priority.
  165.  
  166.    Negative values are special.
  167.    -1 is used to mark a pseudo reg which has a constant or memory equivalent
  168.    and is used infrequently enough that it should not get a hard register.
  169.    -2 is used to mark a pseudo reg for a parameter, when a frame pointer
  170.    is not required.  global-alloc.c makes an allocno for this but does
  171.    not try to assign a hard register to it.  */
  172.  
  173. int *reg_live_length;
  174.  
  175. /* Element N is the next insn that uses (hard or pseudo) register number N
  176.    within the current basic block; or zero, if there is no such insn.
  177.    This is valid only during the final backward scan in propagate_block.  */
  178.  
  179. static rtx *reg_next_use;
  180.  
  181. /* Size of a regset for the current function,
  182.    in (1) bytes and (2) elements.  */
  183.  
  184. int regset_bytes;
  185. int regset_size;
  186.  
  187. /* Element N is first insn in basic block N.
  188.    This info lasts until we finish compiling the function.  */
  189.  
  190. rtx *basic_block_head;
  191.  
  192. /* Element N is last insn in basic block N.
  193.    This info lasts until we finish compiling the function.  */
  194.  
  195. rtx *basic_block_end;
  196.  
  197. /* Element N is a regset describing the registers live
  198.    at the start of basic block N.
  199.    This info lasts until we finish compiling the function.  */
  200.  
  201. regset *basic_block_live_at_start;
  202.  
  203. /* Regset of regs live when calls to `setjmp'-like functions happen.  */
  204.  
  205. regset regs_live_at_setjmp;
  206.  
  207. /* Element N is nonzero if control can drop into basic block N
  208.    from the preceding basic block.  Freed after life_analysis.  */
  209.  
  210. static char *basic_block_drops_in;
  211.  
  212. /* Element N is depth within loops of basic block number N.
  213.    Freed after life_analysis.  */
  214.  
  215. static short *basic_block_loop_depth;
  216.  
  217. /* Element N nonzero if basic block N can actually be reached.
  218.    Vector exists only during find_basic_blocks.  */
  219.  
  220. static char *block_live_static;
  221.  
  222. /* Depth within loops of basic block being scanned for lifetime analysis,
  223.    plus one.  This is the weight attached to references to registers.  */
  224.  
  225. static int loop_depth;
  226.  
  227. /* Define AUTO_INC_DEC if machine has any kind of incrementing
  228.    or decrementing addressing.  */
  229.  
  230. #ifdef HAVE_PRE_DECREMENT
  231. #define AUTO_INC_DEC
  232. #endif
  233.  
  234. #ifdef HAVE_PRE_INCREMENT
  235. #define AUTO_INC_DEC
  236. #endif
  237.  
  238. #ifdef HAVE_POST_DECREMENT
  239. #define AUTO_INC_DEC
  240. #endif
  241.  
  242. #ifdef HAVE_POST_INCREMENT
  243. #define AUTO_INC_DEC
  244. #endif
  245.  
  246. /* Forward declarations */
  247. static void find_basic_blocks ();
  248. static void life_analysis ();
  249. static void mark_label_ref ();
  250. void allocate_for_life_analysis (); /* Used also in stupid_life_analysis */
  251. static void init_regset_vector ();
  252. static void propagate_block ();
  253. static void mark_set_regs ();
  254. static void mark_used_regs ();
  255. static int insn_dead_p ();
  256. static int try_pre_increment ();
  257. static int try_pre_increment_1 ();
  258. static rtx find_use_as_address ();
  259. static int volatile_refs_p ();
  260. void dump_flow_info ();
  261.  
  262. /* Find basic blocks of the current function and perform data flow analysis.
  263.    F is the first insn of the function and NREGS the number of register numbers
  264.    in use.  */
  265.  
  266. void
  267. flow_analysis (f, nregs, file)
  268.      rtx f;
  269.      int nregs;
  270.      FILE *file;
  271. {
  272.   register rtx insn;
  273.   register int i;
  274.   register int max_uid = 0;
  275.  
  276.   /* Count the basic blocks.  Also find maximum insn uid value used.  */
  277.  
  278.   {
  279.     register RTX_CODE prev_code = JUMP_INSN;
  280.     register RTX_CODE code;
  281.  
  282.     for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
  283.       {
  284.     code = GET_CODE (insn);
  285.     if (INSN_UID (insn) > max_uid)
  286.       max_uid = INSN_UID (insn);
  287.     if (code == CODE_LABEL
  288.         || (prev_code != INSN && prev_code != CALL_INSN
  289.         && prev_code != CODE_LABEL
  290.         && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
  291.       i++;
  292.     if (code != NOTE)
  293.       prev_code = code;
  294.       }
  295.   }
  296.  
  297.   /* Allocate some tables that last till end of compiling this function
  298.      and some needed only in find_basic_blocks and life_analysis.  */
  299.  
  300.   n_basic_blocks = i;
  301.   basic_block_head = (rtx *) oballoc (n_basic_blocks * sizeof (rtx));
  302.   basic_block_end = (rtx *) oballoc (n_basic_blocks * sizeof (rtx));
  303.   basic_block_drops_in = (char *) alloca (n_basic_blocks);
  304.   basic_block_loop_depth = (short *) alloca (n_basic_blocks * sizeof (short));
  305.   uid_block_number = (short *) alloca ((max_uid + 1) * sizeof (short));
  306.   uid_volatile = (char *) alloca (max_uid + 1);
  307.   bzero (uid_volatile, max_uid + 1);
  308.  
  309.   find_basic_blocks (f);
  310.   life_analysis (f, nregs);
  311.   if (file)
  312.     dump_flow_info (file);
  313.  
  314.   basic_block_drops_in = 0;
  315.   uid_block_number = 0;
  316.   basic_block_loop_depth = 0;
  317. }
  318.  
  319. /* Find all basic blocks of the function whose first insn is F.
  320.    Store the correct data in the tables that describe the basic blocks,
  321.    set up the chains of references for each CODE_LABEL, and
  322.    delete any entire basic blocks that cannot be reached.  */
  323.  
  324. static void
  325. find_basic_blocks (f)
  326.      rtx f;
  327. {
  328.   register rtx insn;
  329.   register int i;
  330.  
  331.   /* Initialize the ref chain of each label to 0.  */
  332.   /* Record where all the blocks start and end and their depth in loops.  */
  333.   /* For each insn, record the block it is in.  */
  334.  
  335.   {
  336.     register RTX_CODE prev_code = JUMP_INSN;
  337.     register RTX_CODE code;
  338.     int depth = 1;
  339.  
  340.     for (insn = f, i = -1; insn; insn = NEXT_INSN (insn))
  341.       {
  342.     code = GET_CODE (insn);
  343.     if (code == NOTE)
  344.       {
  345.         if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
  346.           depth++;
  347.         else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
  348.           depth--;
  349.       }
  350.     else if (code == CODE_LABEL
  351.          || (prev_code != INSN && prev_code != CALL_INSN
  352.              && prev_code != CODE_LABEL
  353.              && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
  354.       {
  355.         basic_block_head[++i] = insn;
  356.         basic_block_end[i] = insn;
  357.         basic_block_loop_depth[i] = depth;
  358.         if (code == CODE_LABEL)
  359.           LABEL_REFS (insn) = insn;
  360.       }
  361.     else if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
  362.       basic_block_end[i] = insn;
  363.     BLOCK_NUM (insn) = i;
  364.     if (code != NOTE)
  365.       prev_code = code;
  366.       }
  367.     if (i + 1 != n_basic_blocks)
  368.       abort ();
  369.   }
  370.  
  371.   /* Record which basic blocks control can drop in to.  */
  372.  
  373.   {
  374.     register int i;
  375.     for (i = 0; i < n_basic_blocks; i++)
  376.       {
  377.     register rtx insn = PREV_INSN (basic_block_head[i]);
  378.     /* TEMP1 is used to avoid a bug in Sequent's compiler.  */
  379.     register int temp1;
  380.     while (insn && GET_CODE (insn) == NOTE)
  381.       insn = PREV_INSN (insn);
  382.     temp1 = insn && GET_CODE (insn) != BARRIER;
  383.     basic_block_drops_in[i] = temp1;
  384.       }
  385.   }
  386.  
  387.   /* Now find which basic blocks can actually be reached
  388.      and put all jump insns' LABEL_REFS onto the ref-chains
  389.      of their target labels.  */
  390.  
  391.   if (n_basic_blocks > 0)
  392.     {
  393.       register char *block_live = (char *) alloca (n_basic_blocks);
  394.       register char *block_marked = (char *) alloca (n_basic_blocks);
  395.       int something_marked = 1;
  396.  
  397.       /* Initialize with just block 0 reachable and no blocks marked.  */
  398.  
  399.       bzero (block_live, n_basic_blocks);
  400.       bzero (block_marked, n_basic_blocks);
  401.       block_live[0] = 1;
  402.       block_live_static = block_live;
  403.  
  404.       /* Pass over all blocks, marking each block that is reachable
  405.      and has not yet been marked.
  406.      Keep doing this until, in one pass, no blocks have been marked.
  407.      Then blocks_live and blocks_marked are identical and correct.
  408.      In addition, all jumps actually reachable have been marked.  */
  409.  
  410.       while (something_marked)
  411.     {
  412.       something_marked = 0;
  413.       for (i = 0; i < n_basic_blocks; i++)
  414.         if (block_live[i] && !block_marked[i])
  415.           {
  416.         block_marked[i] = 1;
  417.         something_marked = 1;
  418.         if (i + 1 < n_basic_blocks && basic_block_drops_in[i + 1])
  419.           block_live[i + 1] = 1;
  420.         insn = basic_block_end[i];
  421.         if (GET_CODE (insn) == JUMP_INSN)
  422.           mark_label_ref (PATTERN (insn), insn, 0);
  423.           }
  424.     }
  425.  
  426.       /* Now delete the code for any basic blocks that can't be reached.
  427.      They can occur because jump_optimize does not recognize
  428.      unreachable loops as unreachable.  */
  429.  
  430.       for (i = 0; i < n_basic_blocks; i++)
  431.     if (!block_live[i])
  432.       {
  433.         insn = basic_block_head[i];
  434.         while (1)
  435.           {
  436.         if (GET_CODE (insn) == BARRIER)
  437.           abort ();
  438.         if (GET_CODE (insn) != NOTE)
  439.           {
  440.             PUT_CODE (insn, NOTE);
  441.             NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  442.             NOTE_SOURCE_FILE (insn) = 0;
  443.           }
  444.         if (insn == basic_block_end[i])
  445.           {
  446.             /* BARRIERs are between basic blocks, not part of one.
  447.                Delete a BARRIER if the preceding jump is deleted.
  448.                We cannot alter a BARRIER into a NOTE
  449.                because it is too short; but we can really delete
  450.                it because it is not part of a basic block.  */
  451.             if (NEXT_INSN (insn) != 0
  452.             && GET_CODE (NEXT_INSN (insn)) == BARRIER)
  453.               delete_insn (NEXT_INSN (insn));
  454.             break;
  455.           }
  456.         insn = NEXT_INSN (insn);
  457.           }
  458.         /* Each time we delete some basic blocks,
  459.            see if there is a jump around them that is
  460.            being turned into a no-op.  If so, delete it.  */
  461.  
  462.         if (block_live[i - 1])
  463.           {
  464.         register int j;
  465.         for (j = i; j < n_basic_blocks; j++)
  466.           if (block_live[j])
  467.             {
  468.               insn = basic_block_end[i - 1];
  469.               if (GET_CODE (insn) == JUMP_INSN
  470.               && JUMP_LABEL (insn) != 0
  471.               && INSN_UID (JUMP_LABEL (insn)) != 0
  472.               && BLOCK_NUM (JUMP_LABEL (insn)) == j)
  473.             {
  474.               PUT_CODE (insn, NOTE);
  475.               NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  476.               NOTE_SOURCE_FILE (insn) = 0;
  477.               if (GET_CODE (NEXT_INSN (insn)) != BARRIER)
  478.                 abort ();
  479.               delete_insn (NEXT_INSN (insn));
  480.             }
  481.               break;
  482.             }
  483.           }
  484.       }
  485.     }
  486. }
  487.  
  488. /* Check expression X for label references;
  489.    if one is found, add INSN to the label's chain of references.
  490.  
  491.    CHECKDUP means check for and avoid creating duplicate references
  492.    from the same insn.  Such duplicates do no serious harm but
  493.    can slow life analysis.  CHECKDUP is set only when duplicates
  494.    are likely.  */
  495.  
  496. static void
  497. mark_label_ref (x, insn, checkdup)
  498.      rtx x, insn;
  499.      int checkdup;
  500. {
  501.   register RTX_CODE code = GET_CODE (x);
  502.   register int i;
  503.   register char *fmt;
  504.  
  505.   if (code == LABEL_REF)
  506.     {
  507.       register rtx label = XEXP (x, 0);
  508.       register rtx y;
  509.       if (GET_CODE (label) != CODE_LABEL)
  510.     abort ();
  511.       /* If the label was never emitted, this insn is junk,
  512.      but avoid a crash trying to refer to BLOCK_NUM (label).
  513.      This can happen as a result of a syntax error
  514.      and a diagnostic has already been printed.  */
  515.       if (INSN_UID (label) == 0)
  516.     return;
  517.       CONTAINING_INSN (x) = insn;
  518.       /* if CHECKDUP is set, check for duplicate ref from same insn
  519.      and don't insert.  */
  520.       if (checkdup)
  521.     for (y = LABEL_REFS (label); y != label; y = LABEL_NEXTREF (y))
  522.       if (CONTAINING_INSN (y) == insn)
  523.         return;
  524.       LABEL_NEXTREF (x) = LABEL_REFS (label);
  525.       LABEL_REFS (label) = x;
  526.       block_live_static[BLOCK_NUM (label)] = 1;
  527.       return;
  528.     }
  529.  
  530.   fmt = GET_RTX_FORMAT (code);
  531.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  532.     {
  533.       if (fmt[i] == 'e')
  534.     mark_label_ref (XEXP (x, i), insn, 0);
  535.       if (fmt[i] == 'E')
  536.     {
  537.       register int j;
  538.       for (j = 0; j < XVECLEN (x, i); j++)
  539.         mark_label_ref (XVECEXP (x, i, j), insn, 1);
  540.     }
  541.     }
  542. }
  543.  
  544. /* Determine the which registers are live at the start of each
  545.    basic block of the function whose first insn is F.
  546.    NREGS is the number of registers used in F.
  547.    We allocate the vector basic_block_live_at_start
  548.    and the regsets that it points to, and fill them with the data.
  549.    regset_size and regset_bytes are also set here.  */
  550.  
  551. static void
  552. life_analysis (f, nregs)
  553.      rtx f;
  554.      int nregs;
  555. {
  556.   register regset tem;
  557.   int first_pass;
  558.   int changed;
  559.   /* For each basic block, a bitmask of regs
  560.      live on exit from the block.  */
  561.   regset *basic_block_live_at_end;
  562.   /* For each basic block, a bitmask of regs
  563.      live on entry to a successor-block of this block.
  564.      If this does not match basic_block_live_at_end,
  565.      that must be updated, and the block must be rescanned.  */
  566.   regset *basic_block_new_live_at_end;
  567.   /* For each basic block, a bitmask of regs
  568.      whose liveness at the end of the basic block
  569.      can make a difference in which regs are live on entry to the block.
  570.      These are the regs that are set within the basic block,
  571.      possibly excluding those that are used after they are set.  */
  572.   regset *basic_block_significant;
  573.   register int i;
  574.   rtx insn;
  575.  
  576.   max_regno = nregs;
  577.  
  578.   bzero (regs_ever_live, sizeof regs_ever_live);
  579.  
  580.   /* Allocate and zero out many data structures
  581.      that will record the data from lifetime analysis.  */
  582.  
  583.   allocate_for_life_analysis ();
  584.  
  585.   reg_next_use = (rtx *) alloca (nregs * sizeof (rtx));
  586.   bzero (reg_next_use, nregs * sizeof (rtx));
  587.  
  588.   /* Set up several regset-vectors used internally within this function.
  589.      Their meanings are documented above, with their declarations.  */
  590.  
  591.   basic_block_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset));
  592.   tem = (regset) alloca (n_basic_blocks * regset_bytes);
  593.   bzero (tem, n_basic_blocks * regset_bytes);
  594.   init_regset_vector (basic_block_live_at_end, tem, n_basic_blocks, regset_bytes);
  595.  
  596.   basic_block_new_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset));
  597.   tem = (regset) alloca (n_basic_blocks * regset_bytes);
  598.   bzero (tem, n_basic_blocks * regset_bytes);
  599.   init_regset_vector (basic_block_new_live_at_end, tem, n_basic_blocks, regset_bytes);
  600.  
  601.   basic_block_significant = (regset *) alloca (n_basic_blocks * sizeof (regset));
  602.   tem = (regset) alloca (n_basic_blocks * regset_bytes);
  603.   bzero (tem, n_basic_blocks * regset_bytes);
  604.   init_regset_vector (basic_block_significant, tem, n_basic_blocks, regset_bytes);
  605.  
  606.   /* Record which insns refer to any volatile memory
  607.      or for any reason can't be deleted just because they are dead stores.  */
  608.  
  609.   for (insn = f; insn; insn = NEXT_INSN (insn))
  610.     {
  611.       enum rtx_code code1 = GET_CODE (insn);
  612.       if (code1 == CALL_INSN)
  613.     INSN_VOLATILE (insn) = 1;
  614.       else if (code1 == INSN || code1 == JUMP_INSN)
  615.     {
  616.       if (GET_CODE (PATTERN (insn)) != USE)
  617.         INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn));
  618.     }
  619.     }
  620.  
  621.   if (n_basic_blocks > 0)
  622. #ifdef EXIT_IGNORE_STACK
  623.     if (! (EXIT_IGNORE_STACK) || ! frame_pointer_needed)
  624. #endif
  625.       {
  626.     /* If exiting needs the right stack value,
  627.        consider the stack pointer live at the end of the function.  */
  628.     basic_block_live_at_end[n_basic_blocks - 1]
  629.       [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
  630.         |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
  631.     basic_block_new_live_at_end[n_basic_blocks - 1]
  632.       [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
  633.         |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
  634.       }
  635.  
  636.   /* Propagate life info through the basic blocks
  637.      around the graph of basic blocks.
  638.  
  639.      This is a relaxation process: each time a new register
  640.      is live at the end of the basic block, we must scan the block
  641.      to determine which registers are, as a consequence, live at the beginning
  642.      of that block.  These registers must then be marked live at the ends
  643.      of all the blocks that can transfer control to that block.
  644.      The process continues until it reaches a fixed point.  */
  645.  
  646.   first_pass = 1;
  647.   changed = 1;
  648.   while (changed)
  649.     {
  650.       changed = 0;
  651.       for (i = n_basic_blocks - 1; i >= 0; i--)
  652.     {
  653.       int consider = first_pass;
  654.       int must_rescan = first_pass;
  655.       register int j;
  656.  
  657.       /* Set CONSIDER if this block needs thinking about at all
  658.          (that is, if the regs live now at the end of it
  659.          are not the same as were live at the end of it when
  660.          we last thought about it).
  661.          Set must_rescan if it needs to be thought about
  662.          instruction by instruction (that is, if any additional
  663.          reg that is live at the end now but was not live there before
  664.          is one of the significant regs of this basic block).  */
  665.  
  666.       for (j = 0; j < regset_size; j++)
  667.         {
  668.           register int x = basic_block_new_live_at_end[i][j]
  669.               & ~basic_block_live_at_end[i][j];
  670.           if (x)
  671.         consider = 1;
  672.           if (x & basic_block_significant[i][j])
  673.         {
  674.           must_rescan = 1;
  675.           consider = 1;
  676.           break;
  677.         }
  678.         }
  679.  
  680.       if (! consider)
  681.         continue;
  682.  
  683.       /* The live_at_start of this block may be changing,
  684.          so another pass will be required after this one.  */
  685.       changed = 1;
  686.  
  687.       if (! must_rescan)
  688.         {
  689.           /* No complete rescan needed;
  690.          just record those variables newly known live at end
  691.          as live at start as well.  */
  692.           for (j = 0; j < regset_size; j++)
  693.         {
  694.           register int x = basic_block_new_live_at_end[i][j]
  695.             & ~basic_block_live_at_end[i][j];
  696.           basic_block_live_at_start[i][j] |= x;
  697.           basic_block_live_at_end[i][j] |= x;
  698.         }
  699.         }
  700.       else
  701.         {
  702.           /* Update the basic_block_live_at_start
  703.          by propagation backwards through the block.  */
  704.           bcopy (basic_block_new_live_at_end[i],
  705.              basic_block_live_at_end[i], regset_bytes);
  706.           bcopy (basic_block_live_at_end[i],
  707.              basic_block_live_at_start[i], regset_bytes);
  708.           propagate_block (basic_block_live_at_start[i],
  709.                    basic_block_head[i], basic_block_end[i], 0,
  710.                    first_pass ? basic_block_significant[i] : 0,
  711.                    i);
  712.         }
  713.  
  714.       {
  715.         register rtx jump, head;
  716.         /* Update the basic_block_new_live_at_end's of the block
  717.            that falls through into this one (if any).  */
  718.         head = basic_block_head[i];
  719.         jump = PREV_INSN (head);
  720.         if (basic_block_drops_in[i])
  721.           {
  722.         register from_block = BLOCK_NUM (jump);
  723.         register int j;
  724.         for (j = 0; j < regset_size; j++)
  725.           basic_block_new_live_at_end[from_block][j]
  726.             |= basic_block_live_at_start[i][j];
  727.           }
  728.         /* Update the basic_block_new_live_at_end's of
  729.            all the blocks that jump to this one.  */
  730.         if (GET_CODE (head) == CODE_LABEL)
  731.           for (jump = LABEL_REFS (head);
  732.            jump != head;
  733.            jump = LABEL_NEXTREF (jump))
  734.         {
  735.           register from_block = BLOCK_NUM (CONTAINING_INSN (jump));
  736.           register int j;
  737.           for (j = 0; j < regset_size; j++)
  738.             basic_block_new_live_at_end[from_block][j]
  739.               |= basic_block_live_at_start[i][j];
  740.         }
  741.       }
  742.     }
  743.       first_pass = 0;
  744.     }
  745.  
  746.   /* Process the regs live at the beginning of the function.
  747.      Mark them as not local to any one basic block.  */
  748.  
  749.   if (n_basic_blocks > 0)
  750.     for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  751.       if (basic_block_live_at_start[0][i / REGSET_ELT_BITS]
  752.       & (1 << (i % REGSET_ELT_BITS)))
  753.     reg_basic_block[i] = REG_BLOCK_GLOBAL;
  754.  
  755.   /* Now the life information is accurate.
  756.      Make one more pass over each basic block
  757.      to delete dead stores, create autoincrement addressing
  758.      and record how many times each register is used, is set, or dies.
  759.  
  760.      To save time, we operate directly in basic_block_live_at_end[i],
  761.      thus destroying it (in fact, converting it into a copy of
  762.      basic_block_live_at_start[i]).  This is ok now because
  763.      basic_block_live_at_end[i] is no longer used past this point.  */
  764.  
  765.   for (i = 0; i < n_basic_blocks; i++)
  766.     {
  767.       propagate_block (basic_block_live_at_end[i],
  768.                basic_block_head[i], basic_block_end[i], 1, 0, i);
  769.     }
  770. }
  771.  
  772. /* Subroutines of life analysis.  */
  773.  
  774. /* Allocate the permanent data structures that represent the results
  775.    of life analysis.  Not static since used also for stupid life analysis.  */
  776.  
  777. void
  778. allocate_for_life_analysis ()
  779. {
  780.   register int i;
  781.   register regset tem;
  782.  
  783.   regset_size = ((max_regno + REGSET_ELT_BITS - 1) / REGSET_ELT_BITS);
  784.   regset_bytes = regset_size * sizeof (*(regset)0);
  785.  
  786.   reg_n_refs = (short *) oballoc (max_regno * sizeof (short));
  787.   bzero (reg_n_refs, max_regno * sizeof (short));
  788.  
  789.   reg_n_sets = (short *) oballoc (max_regno * sizeof (short));
  790.   bzero (reg_n_sets, max_regno * sizeof (short));
  791.  
  792.   reg_n_deaths = (short *) oballoc (max_regno * sizeof (short));
  793.   bzero (reg_n_deaths, max_regno * sizeof (short));
  794.  
  795.   reg_live_length = (int *) oballoc (max_regno * sizeof (int));
  796.   bzero (reg_live_length, max_regno * sizeof (int));
  797.  
  798.   reg_crosses_call = (char *) oballoc (max_regno);
  799.   bzero (reg_crosses_call, max_regno);
  800.  
  801.   reg_basic_block = (short *) oballoc (max_regno * sizeof (short));
  802.   for (i = 0; i < max_regno; i++)
  803.     reg_basic_block[i] = REG_BLOCK_UNKNOWN;
  804.  
  805.   basic_block_live_at_start = (regset *) oballoc (n_basic_blocks * sizeof (regset));
  806.   tem = (regset) oballoc (n_basic_blocks * regset_bytes);
  807.   bzero (tem, n_basic_blocks * regset_bytes);
  808.   init_regset_vector (basic_block_live_at_start, tem, n_basic_blocks, regset_bytes);
  809.  
  810.   regs_live_at_setjmp = (regset) oballoc (regset_bytes);
  811.   bzero (regs_live_at_setjmp, regset_bytes);
  812. }
  813.  
  814. /* Make each element of VECTOR point at a regset,
  815.    taking the space for all those regsets from SPACE.
  816.    SPACE is of type regset, but it is really as long as NELTS regsets.
  817.    BYTES_PER_ELT is the number of bytes in one regset.  */
  818.  
  819. static void
  820. init_regset_vector (vector, space, nelts, bytes_per_elt)
  821.      regset *vector;
  822.      regset space;
  823.      int nelts;
  824.      int bytes_per_elt;
  825. {
  826.   register int i;
  827.   register regset p = space;
  828.  
  829.   for (i = 0; i < nelts; i++)
  830.     {
  831.       vector[i] = p;
  832.       p += bytes_per_elt / sizeof (*p);
  833.     }
  834. }
  835.  
  836. /* Compute the registers live at the beginning of a basic block
  837.    from those live at the end.
  838.  
  839.    When called, OLD contains those live at the end.
  840.    On return, it contains those live at the beginning.
  841.    FIRST and LAST are the first and last insns of the basic block.
  842.  
  843.    FINAL is nonzero if we are doing the final pass which is not
  844.    for computing the life info (since that has already been done)
  845.    but for acting on it.  On this pass, we delete dead stores,
  846.    set up the logical links and dead-variables lists of instructions,
  847.    and merge instructions for autoincrement and autodecrement addresses.
  848.  
  849.    SIGNIFICANT is nonzero only the first time for each basic block.
  850.    If it is nonzero, it points to a regset in which we store
  851.    a 1 for each register that is set within the block.
  852.  
  853.    BNUM is the number of the basic block.  */
  854.  
  855. static void
  856. propagate_block (old, first, last, final, significant, bnum)
  857.      register regset old;
  858.      rtx first;
  859.      rtx last;
  860.      int final;
  861.      regset significant;
  862.      int bnum;
  863. {
  864.   register rtx insn;
  865.   rtx prev;
  866.   regset live;
  867.   regset dead;
  868.  
  869.   /* The following variables are used only if FINAL is nonzero.  */
  870.   /* This vector gets one element for each reg that has been live
  871.      at any point in the basic block that has been scanned so far.
  872.      SOMETIMES_MAX says how many elements are in use so far.
  873.      In each element, OFFSET is the byte-number within a regset
  874.      for the register described by the element, and BIT is a mask
  875.      for that register's bit within the byte.  */
  876.   register struct foo { short offset; short bit; } *regs_sometimes_live;
  877.   int sometimes_max = 0;
  878.   /* This regset has 1 for each reg that we have seen live so far.
  879.      It and REGS_SOMETIMES_LIVE are updated together.  */
  880.   regset maxlive;
  881.  
  882.   loop_depth = basic_block_loop_depth[bnum];
  883.  
  884.   dead = (regset) alloca (regset_bytes);
  885.   live = (regset) alloca (regset_bytes);
  886.  
  887.   if (final)
  888.     {
  889.       register int i, offset, bit;
  890.  
  891.       maxlive = (regset) alloca (regset_bytes);
  892.       bcopy (old, maxlive, regset_bytes);
  893.       regs_sometimes_live
  894.     = (struct foo *) alloca (max_regno * sizeof (struct foo));
  895.  
  896.       /* Process the regs live at the end of the block.
  897.      Enter them in MAXLIVE and REGS_SOMETIMES_LIVE.
  898.      Also mark them as not local to any one basic block.  */
  899.  
  900.       for (offset = 0, i = 0; offset < regset_size; offset++)
  901.     for (bit = 1; bit; bit <<= 1, i++)
  902.       {
  903.         if (i == max_regno)
  904.           break;
  905.         if (old[offset] & bit)
  906.           {
  907.         reg_basic_block[i] = REG_BLOCK_GLOBAL;
  908.         regs_sometimes_live[sometimes_max].offset = offset;
  909.         regs_sometimes_live[sometimes_max].bit = i % REGSET_ELT_BITS;
  910.         sometimes_max++;
  911.           }
  912.       }
  913.     }
  914.  
  915.   /* Scan the block an insn at a time from end to beginning.  */
  916.  
  917.   for (insn = last; ; insn = prev)
  918.     {
  919.       prev = PREV_INSN (insn);
  920.  
  921.       /* If this is a call to `setjmp' et al,
  922.      warn if any non-volatile datum is live.  */
  923.  
  924.       if (final && GET_CODE (insn) == NOTE
  925.       && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)
  926.     {
  927.       int i;
  928.       for (i = 0; i < regset_size; i++)
  929.         regs_live_at_setjmp[i] |= old[i];
  930.     }
  931.  
  932.       /* Update the life-status of regs for this insn.
  933.      First DEAD gets which regs are set in this insn
  934.      then LIVE gets which regs are used in this insn.
  935.      Then the regs live before the insn
  936.      are those live after, with DEAD regs turned off,
  937.      and then LIVE regs turned on.  */
  938.  
  939.       if (GET_CODE (insn) == INSN
  940.       || GET_CODE (insn) == JUMP_INSN
  941.       || GET_CODE (insn) == CALL_INSN)
  942.     {
  943.       register int i;
  944.       rtx note = find_reg_note (insn, REG_RETVAL, 0);
  945.  
  946.       /* If an instruction consists of just dead store(s) on final pass,
  947.          "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
  948.          We could really delete it with delete_insn, but that
  949.          can cause trouble for first or last insn in a basic block.  */
  950.       if (final && insn_dead_p (PATTERN (insn), old, 1)
  951.           /* Don't delete something that refers to volatile storage!  */
  952.           && ! INSN_VOLATILE (insn))
  953.         {
  954.           PUT_CODE (insn, NOTE);
  955.           NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  956.           NOTE_SOURCE_FILE (insn) = 0;
  957.           /* If this insn is copying the return value from a library call,
  958.          delete the entire library call.  */
  959.           if (note)
  960.         {
  961.           rtx first = XEXP (note, 0);
  962.           rtx prev = insn;
  963.           while (first->volatil)
  964.             first = NEXT_INSN (first);
  965.           while (prev != first)
  966.             {
  967.               prev = PREV_INSN (prev);
  968.               PUT_CODE (prev, NOTE);
  969.               NOTE_LINE_NUMBER (prev) = NOTE_INSN_DELETED;
  970.               NOTE_SOURCE_FILE (prev) = 0;
  971.             }
  972.         }
  973.           goto flushed;
  974.         }
  975.  
  976.       for (i = 0; i < regset_size; i++)
  977.         {
  978.           dead[i] = 0;    /* Faster than bzero here */
  979.           live[i] = 0;    /* since regset_size is usually small */
  980.         }
  981.  
  982.       /* See if this is an increment or decrement that can be
  983.          merged into a following memory address.  */
  984. #ifdef AUTO_INC_DEC
  985.       {
  986.         register rtx x = PATTERN (insn);
  987.         /* Does this instruction increment or decrement a register?  */
  988.         if (final && GET_CODE (x) == SET
  989.         && GET_CODE (SET_DEST (x)) == REG
  990.         && (GET_CODE (SET_SRC (x)) == PLUS
  991.             || GET_CODE (SET_SRC (x)) == MINUS)
  992.         && XEXP (SET_SRC (x), 0) == SET_DEST (x)
  993.         && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
  994.         /* Ok, look for a following memory ref we can combine with.
  995.            If one is found, change the memory ref to a PRE_INC
  996.            or PRE_DEC, cancel this insn, and return 1.
  997.            Return 0 if nothing has been done.  */
  998.         && try_pre_increment_1 (insn))
  999.           goto flushed;
  1000.       }
  1001. #endif /* AUTO_INC_DEC */
  1002.  
  1003.       /* If this is not the final pass, and this insn is copying the
  1004.          value of a library call and it's dead, don't scan the
  1005.          insns that perform the library call, so that the call's
  1006.          arguments are not marked live.  */
  1007.       if (note && insn_dead_p (PATTERN (insn), old, 1))
  1008.         {
  1009.           /* Mark the dest reg as `significant'.  */
  1010.           mark_set_regs (old, dead, PATTERN (insn), 0, significant);
  1011.  
  1012.           insn = XEXP (note, 0);
  1013.           prev = PREV_INSN (insn);
  1014.         }
  1015.       else if (SET_DEST (PATTERN (insn)) == stack_pointer_rtx
  1016.            && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
  1017.            && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
  1018.            && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
  1019.         /* These insns, if not dead stores, have no effect on life.  */
  1020.         ;
  1021.       else
  1022.         {
  1023.           /* LIVE gets the regs used in INSN; DEAD gets those set by it.  */
  1024.           mark_set_regs (old, dead, PATTERN (insn), final ? insn : 0,
  1025.                  significant);
  1026.           mark_used_regs (old, live, PATTERN (insn), final, insn);
  1027.  
  1028.           /* Update OLD for the registers used or set.  */
  1029.           for (i = 0; i < regset_size; i++)
  1030.         {
  1031.           old[i] &= ~dead[i];
  1032.           old[i] |= live[i];
  1033.         }
  1034.  
  1035.           if (GET_CODE (insn) == CALL_INSN)
  1036.         {
  1037.           register int i;
  1038.  
  1039.           /* Each call clobbers all call-clobbered regs.
  1040.              Note that the function-value reg is one of these, and
  1041.              mark_set_regs has already had a chance to handle it.  */
  1042.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1043.             if (call_used_regs[i])
  1044.               old[i / REGSET_ELT_BITS]
  1045.             &= ~(1 << (i % REGSET_ELT_BITS));
  1046.  
  1047.           /* The stack ptr is used (honorarily) by a CALL insn.  */
  1048.           old[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
  1049.             |= (1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS));
  1050.  
  1051.           if (final)
  1052.             {
  1053.               /* Any regs live at the time of a call instruction
  1054.              must not go in a register clobbered by calls.
  1055.              Find all regs now live and record this for them.  */
  1056.  
  1057.               register struct foo *p = regs_sometimes_live;
  1058.  
  1059.               for (i = 0; i < sometimes_max; i++, p++)
  1060.             {
  1061.               if (old[p->offset]
  1062.                   & (1 << p->bit))
  1063.                 reg_crosses_call[p->offset * REGSET_ELT_BITS + p->bit] = 1;
  1064.             }
  1065.             }
  1066.         }
  1067.         }
  1068.  
  1069.       /* On final pass, add any additional sometimes-live regs
  1070.          into MAXLIVE and REGS_SOMETIMES_LIVE.
  1071.          Also update counts of how many insns each reg is live at.  */
  1072.  
  1073.       if (final)
  1074.         {
  1075.           for (i = 0; i < regset_size; i++)
  1076.         {
  1077.           register int diff = live[i] & ~maxlive[i];
  1078.  
  1079.           if (diff)
  1080.             {
  1081.               register int regno;
  1082.               maxlive[i] |= diff;
  1083.               for (regno = 0; diff && regno < REGSET_ELT_BITS; regno++)
  1084.             if (diff & (1 << regno))
  1085.               {
  1086.                 regs_sometimes_live[sometimes_max].offset = i;
  1087.                 regs_sometimes_live[sometimes_max].bit = regno;
  1088.                 diff &= ~ (1 << regno);
  1089.                 sometimes_max++;
  1090.               }
  1091.             }
  1092.         }
  1093.  
  1094.           {
  1095.         register struct foo *p = regs_sometimes_live;
  1096.         for (i = 0; i < sometimes_max; i++, p++)
  1097.           {
  1098.             if (old[p->offset] & (1 << p->bit))
  1099.               reg_live_length[p->offset * REGSET_ELT_BITS + p->bit]++;
  1100.           }
  1101.           }
  1102.         }
  1103.     }
  1104.     flushed: ;
  1105.       if (insn == first)
  1106.     break;
  1107.     }
  1108. }
  1109.  
  1110. /* Return 1 if X (the body of an insn, or part of it) is just dead stores
  1111.    (SET expressions whose destinations are registers dead after the insn).
  1112.    NEEDED is the regset that says which regs are alive after the insn.  */
  1113.  
  1114. static int
  1115. insn_dead_p (x, needed, strict_low_ok)
  1116.      rtx x;
  1117.      regset needed;
  1118.      int strict_low_ok;
  1119. {
  1120.   register RTX_CODE code = GET_CODE (x);
  1121. #if 0
  1122.   /* Make sure insns to set the stack pointer are never deleted.  */
  1123.   needed[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
  1124.     |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
  1125. #endif
  1126.  
  1127.   /* If setting something that's a reg or part of one,
  1128.      see if that register's altered value will be live.  */
  1129.  
  1130.   if (code == SET)
  1131.     {
  1132.       register rtx r = SET_DEST (x);
  1133.       /* A SET that makes space on the stack cannot be dead.
  1134.      Even if this function never uses this stack pointer value,
  1135.      signal handlers do!  */
  1136.       if (r == stack_pointer_rtx
  1137. #ifdef STACK_GROWS_DOWNWARD
  1138.       && GET_CODE (SET_SRC (x)) == MINUS
  1139. #else
  1140.       && GET_CODE (SET_SRC (x)) == PLUS
  1141. #endif
  1142.       && XEXP (SET_SRC (x), 0) == r)
  1143.     return 0;
  1144.       /* A SET that is a subroutine call cannot be dead.  */
  1145.       if (GET_CODE (SET_SRC (x)) == CALL)
  1146.     return 0;
  1147.       while (GET_CODE (r) == SUBREG
  1148.          || (strict_low_ok && GET_CODE (r) == STRICT_LOW_PART)
  1149.          || GET_CODE (r) == ZERO_EXTRACT
  1150.          || GET_CODE (r) == SIGN_EXTRACT)
  1151.     r = SUBREG_REG (r);
  1152.       if (GET_CODE (r) == REG)
  1153.     {
  1154.       register int regno = REGNO (r);
  1155.       register int offset = regno / REGSET_ELT_BITS;
  1156.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1157.       return (needed[offset] & bit) == 0;
  1158.     }
  1159.     }
  1160.   /* If performing several activities,
  1161.      insn is dead if each activity is individually dead.
  1162.      Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
  1163.      that's inside a PARALLEL doesn't make the insn worth keeping.  */
  1164.   else if (code == PARALLEL)
  1165.     {
  1166.       register int i = XVECLEN (x, 0);
  1167.       for (i--; i >= 0; i--)
  1168.     {
  1169.       rtx elt = XVECEXP (x, 0, i);
  1170.       if (!insn_dead_p (elt, needed, strict_low_ok)
  1171.           && GET_CODE (elt) != CLOBBER
  1172.           && GET_CODE (elt) != USE)
  1173.         return 0;
  1174.     }
  1175.       return 1;
  1176.     }
  1177.   /* We do not check CLOBBER or USE here.
  1178.      An insn consisting of just a CLOBBER or just a USE
  1179.      should not be deleted.  */
  1180.   return 0;
  1181. }
  1182.  
  1183. /* Return 1 if register REGNO was used before it was set.
  1184.    In other words, if it is live at function entry.  */
  1185.  
  1186. int
  1187. regno_uninitialized (regno)
  1188.      int regno;
  1189. {
  1190.   return (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
  1191.       & (1 << (regno % REGSET_ELT_BITS)));
  1192. }
  1193.  
  1194. /* 1 if register REGNO was alive at a place where `setjmp' was called
  1195.    and was set more than once.  Such regs may be clobbered by `longjmp'.  */
  1196.  
  1197. int
  1198. regno_clobbered_at_setjmp (regno)
  1199.      int regno;
  1200. {
  1201.   return (reg_n_sets[regno] > 1
  1202.       && (regs_live_at_setjmp[regno / REGSET_ELT_BITS]
  1203.           & (1 << (regno % REGSET_ELT_BITS))));
  1204. }
  1205.  
  1206. /* Process the registers that are set within X.
  1207.    Their bits are set to 1 in the regset DEAD,
  1208.    because they are dead prior to this insn.
  1209.  
  1210.    If INSN is nonzero, it is the insn being processed
  1211.    and the fact that it is nonzero implies this is the FINAL pass
  1212.    in propagate_block.  In this case, various info about register
  1213.    usage is stored, LOG_LINKS fields of insns are set up.  */
  1214.  
  1215. static void mark_set_1 ();
  1216.  
  1217. static void
  1218. mark_set_regs (needed, dead, x, insn, significant)
  1219.      regset needed;
  1220.      regset dead;
  1221.      rtx x;
  1222.      rtx insn;
  1223.      regset significant;
  1224. {
  1225.   register RTX_CODE code = GET_CODE (x);
  1226.  
  1227.   if (code == SET || code == CLOBBER)
  1228.     mark_set_1 (needed, dead, x, insn, significant);
  1229.   else if (code == PARALLEL)
  1230.     {
  1231.       register int i;
  1232.       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  1233.     {
  1234.       code = GET_CODE (XVECEXP (x, 0, i));
  1235.       if (code == SET || code == CLOBBER)
  1236.         mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant);
  1237.     }
  1238.     }
  1239. }
  1240.  
  1241. /* Process a single SET rtx, X.  */
  1242.  
  1243. static void
  1244. mark_set_1 (needed, dead, x, insn, significant)
  1245.      regset needed;
  1246.      regset dead;
  1247.      rtx x;
  1248.      rtx insn;
  1249.      regset significant;
  1250. {
  1251.   register int regno;
  1252.   register rtx reg = SET_DEST (x);
  1253.  
  1254.   if (reg == 0)
  1255.     return;
  1256.  
  1257.   if (GET_CODE (reg) == SUBREG)
  1258.     {
  1259.       /* Modifying just one hardware register
  1260.      of a multi-register value does not count as "setting"
  1261.      for live-dead analysis.  Parts of the previous value
  1262.      might still be significant below this insn.  */
  1263.       if (REG_SIZE (SUBREG_REG (reg)) > REG_SIZE (reg))
  1264.     return;
  1265.  
  1266.       reg = SUBREG_REG (reg);
  1267.     }
  1268.  
  1269.   if (GET_CODE (reg) == REG
  1270.       && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM)
  1271.       && regno != ARG_POINTER_REGNUM)
  1272.     /* && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
  1273.     {
  1274.       register int offset = regno / REGSET_ELT_BITS;
  1275.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1276.       int is_needed = 0;
  1277.  
  1278.       /* Mark the reg being set as dead before this insn.  */
  1279.       dead[offset] |= bit;
  1280.       /* Mark it as a significant register for this basic block.  */
  1281.       if (significant)
  1282.     significant[offset] |= bit;
  1283.       /* A hard reg in a wide mode may really be multiple registers.
  1284.      If so, mark all of them just like the first.  */
  1285.       if (regno < FIRST_PSEUDO_REGISTER)
  1286.     {
  1287.       int n;
  1288.  
  1289.       /* Nothing below is needed for the stack pointer; get out asap.
  1290.          Eg, log links aren't needed, since combine won't use them.  */
  1291.       if (regno == STACK_POINTER_REGNUM)
  1292.         return;
  1293.  
  1294.       n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1295.       while (--n > 0)
  1296.         {
  1297.           dead[(regno + n) / REGSET_ELT_BITS]
  1298.         |= 1 << ((regno + n) % REGSET_ELT_BITS);
  1299.           if (significant)
  1300.         significant[(regno + n) / REGSET_ELT_BITS]
  1301.           |= 1 << ((regno + n) % REGSET_ELT_BITS);
  1302.           is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
  1303.                 & 1 << ((regno + n) % REGSET_ELT_BITS));
  1304.         }
  1305.     }
  1306.       /* Additional data to record if this is the final pass.  */
  1307.       if (insn)
  1308.     {
  1309.       register rtx y = reg_next_use[regno];
  1310.       register int blocknum = BLOCK_NUM (insn);
  1311.  
  1312.       /* If this is a hard reg, record this function uses the reg.  */
  1313.  
  1314.       if (regno < FIRST_PSEUDO_REGISTER)
  1315.         {
  1316.           register int i;
  1317.           i = HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1318.           do
  1319.         regs_ever_live[regno + --i] = 1;
  1320.           while (i > 0);
  1321.  
  1322.           if (! ((needed[offset] & bit) || is_needed))
  1323.         {
  1324.           /* Note that dead stores have already been deleted if poss.
  1325.              If we get here, we have found a dead store that cannot
  1326.              be eliminated (because the insn does something useful).
  1327.              Indicate this by marking the reg set as dying here.  */
  1328.           REG_NOTES (insn)
  1329.             = gen_rtx (EXPR_LIST, REG_DEAD,
  1330.                    reg, REG_NOTES (insn));
  1331.           reg_n_deaths[REGNO (reg)]++;
  1332.         }
  1333.           return;
  1334.         }
  1335.  
  1336.       /* Keep track of which basic blocks each reg appears in.  */
  1337.  
  1338.       if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
  1339.         reg_basic_block[regno] = blocknum;
  1340.       else if (reg_basic_block[regno] != blocknum)
  1341.         reg_basic_block[regno] = REG_BLOCK_GLOBAL;
  1342.  
  1343.       /* Count (weighted) references, stores, etc.  */
  1344.       reg_n_refs[regno] += loop_depth;
  1345.       reg_n_sets[regno]++;
  1346.       /* The next use is no longer "next", since a store intervenes.  */
  1347.       reg_next_use[regno] = 0;
  1348.       /* The insns where a reg is live are normally counted elsewhere,
  1349.          but we want the count to include the insn where the reg is set,
  1350.          and the normal counting mechanism would not count it.  */
  1351.       reg_live_length[regno]++;
  1352.       if ((needed[offset] & bit) || is_needed)
  1353.         {
  1354.           /* Make a logical link from the next following insn
  1355.          that uses this register, back to this insn.
  1356.          The following insns have already been processed.  */
  1357.           if (y && (BLOCK_NUM (y) == blocknum))
  1358.         LOG_LINKS (y)
  1359.           = gen_rtx (INSN_LIST, VOIDmode, insn, LOG_LINKS (y));
  1360.         }
  1361.       else
  1362.         {
  1363.           /* Note that dead stores have already been deleted when possible
  1364.          If we get here, we have found a dead store that cannot
  1365.          be eliminated (because the same insn does something useful).
  1366.          Indicate this by marking the reg being set as dying here.  */
  1367.           REG_NOTES (insn)
  1368.         = gen_rtx (EXPR_LIST, REG_DEAD,
  1369.                reg, REG_NOTES (insn));
  1370.           reg_n_deaths[REGNO (reg)]++;
  1371.         }
  1372.     }
  1373.     }
  1374. }
  1375.  
  1376. /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
  1377.    This is done assuming the registers needed from X
  1378.    are those that have 1-bits in NEEDED.
  1379.  
  1380.    On the final pass, FINAL is 1.  This means try for autoincrement
  1381.    and count the uses and deaths of each pseudo-reg.
  1382.  
  1383.    INSN is the containing instruction.  */
  1384.  
  1385. static void
  1386. mark_used_regs (needed, live, x, final, insn)
  1387.      regset needed;
  1388.      regset live;
  1389.      rtx x;
  1390.      rtx insn;
  1391.      int final;
  1392. {
  1393.   register RTX_CODE code;
  1394.   register int regno;
  1395.  
  1396.  retry:
  1397.   code = GET_CODE (x);
  1398.   switch (code)
  1399.     {
  1400.     case LABEL_REF:
  1401.     case SYMBOL_REF:
  1402.     case CONST_INT:
  1403.     case CONST:
  1404.     case CONST_DOUBLE:
  1405.     case CC0:
  1406.     case PC:
  1407.     case CLOBBER:
  1408.     case ADDR_VEC:
  1409.     case ADDR_DIFF_VEC:
  1410.     case ASM_INPUT:
  1411.       return;
  1412.  
  1413. #if defined (HAVE_POST_INCREMENT) || defined (HAVE_POST_DECREMENT)
  1414.     case MEM:
  1415.       /* Here we detect use of an index register which might
  1416.      be good for postincrement or postdecrement.  */
  1417.       if (final)
  1418.     {
  1419.       rtx addr = XEXP (x, 0);
  1420.       register int size = GET_MODE_SIZE (GET_MODE (x));
  1421.  
  1422.       if (GET_CODE (addr) == REG)
  1423.         {
  1424.           register rtx y;
  1425.           regno = REGNO (addr);
  1426.           /* Is the next use an increment that might make auto-increment? */
  1427.           y = reg_next_use[regno];
  1428.           if (y && GET_CODE (PATTERN (y)) == SET
  1429.           && BLOCK_NUM (y) == BLOCK_NUM (insn)
  1430.           /* Can't add side effects to jumps; if reg is spilled and
  1431.              reloaded, there's no way to store back the altered value.  */
  1432.           && GET_CODE (insn) != JUMP_INSN
  1433.           && (y = SET_SRC (PATTERN (y)),
  1434.               (0
  1435. #ifdef HAVE_POST_INCREMENT
  1436.                || GET_CODE (y) == PLUS
  1437. #endif
  1438. #ifdef HAVE_POST_DECREMENT
  1439.                || GET_CODE (y) == MINUS
  1440. #endif
  1441.                )
  1442.               && XEXP (y, 0) == addr
  1443.               && GET_CODE (XEXP (y, 1)) == CONST_INT
  1444.               && INTVAL (XEXP (y, 1)) == size)
  1445.           && dead_or_set_p (reg_next_use[regno], addr))
  1446.         {
  1447.           rtx use = find_use_as_address (PATTERN (insn), addr, 0);
  1448.  
  1449.           /* Make sure this register appears only once in this insn.  */
  1450.           if (use != 0 && use != (rtx) 1)
  1451.             {
  1452.               /* We have found a suitable auto-increment:
  1453.              do POST_INC around the register here,
  1454.              and patch out the increment instruction that follows. */
  1455.               XEXP (x, 0)
  1456.             = gen_rtx (GET_CODE (y) == PLUS ? POST_INC : POST_DEC,
  1457.                    Pmode, addr);
  1458.               /* Record that this insn has an implicit side effect.  */
  1459.               REG_NOTES (insn)
  1460.             = gen_rtx (EXPR_LIST, REG_INC, addr, REG_NOTES (insn));
  1461.  
  1462.               /* Modify the old increment-insn to simply copy
  1463.              the already-incremented value of our register.  */
  1464.               y = reg_next_use[regno];
  1465.               SET_SRC (PATTERN (y)) = addr;
  1466.  
  1467.               /* If that makes it a no-op (copying the register
  1468.              into itself) then change it to a simpler no-op
  1469.              so it won't appear to be a "use" and a "set"
  1470.              of this register.  */
  1471.               if (SET_DEST (PATTERN (y)) == addr)
  1472.             PATTERN (y) = gen_rtx (USE, VOIDmode, const0_rtx);
  1473.  
  1474.               /* Count an extra reference to the reg for the increment.
  1475.              When a reg is incremented.
  1476.              spilling it is worse, so we want to make that
  1477.              less likely.  */
  1478.               reg_n_refs[regno] += loop_depth;
  1479.               /* Count the increment as a setting of the register,
  1480.              even though it isn't a SET in rtl.  */
  1481.               reg_n_sets[regno]++;
  1482.             }
  1483.         }
  1484.         }
  1485.     }
  1486.       break;
  1487. #endif /* HAVE_POST_INCREMENT or HAVE_POST_DECREMENT */
  1488.  
  1489.     case REG:
  1490.       /* See a register other than being set
  1491.      => mark it as needed.  */
  1492.  
  1493.       regno = REGNO (x);
  1494.       if (regno != FRAME_POINTER_REGNUM
  1495.       && regno != ARG_POINTER_REGNUM)
  1496.     /* && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
  1497.     {
  1498.       register int offset = regno / REGSET_ELT_BITS;
  1499.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1500.       int is_needed = 0;
  1501.  
  1502.       live[offset] |= bit;
  1503.       /* A hard reg in a wide mode may really be multiple registers.
  1504.          If so, mark all of them just like the first.  */
  1505.       if (regno < FIRST_PSEUDO_REGISTER)
  1506.         {
  1507.           int n;
  1508.  
  1509.           /* For stack ptr, nothing below here can be necessary,
  1510.          so waste no more time.  */
  1511.           if (regno == STACK_POINTER_REGNUM)
  1512.         return;
  1513.  
  1514.           n = HARD_REGNO_NREGS (regno, GET_MODE (x));
  1515.           while (--n > 0)
  1516.         {
  1517.           live[(regno + n) / REGSET_ELT_BITS]
  1518.             |= 1 << ((regno + n) % REGSET_ELT_BITS);
  1519.           is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
  1520.                 & 1 << ((regno + n) % REGSET_ELT_BITS));
  1521.         }
  1522.         }
  1523.       if (final)
  1524.         {
  1525.           if (regno < FIRST_PSEUDO_REGISTER)
  1526.         {
  1527.           /* If a hard reg is being used,
  1528.              record that this function does use it.  */
  1529.  
  1530.           register int i;
  1531.           i = HARD_REGNO_NREGS (regno, GET_MODE (x));
  1532.           do
  1533.             regs_ever_live[regno + --i] = 1;
  1534.           while (i > 0);
  1535.         }
  1536.           else
  1537.         {
  1538.           /* Keep track of which basic block each reg appears in.  */
  1539.  
  1540.           register int blocknum = BLOCK_NUM (insn);
  1541.  
  1542.           if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
  1543.             reg_basic_block[regno] = blocknum;
  1544.           else if (reg_basic_block[regno] != blocknum)
  1545.             reg_basic_block[regno] = REG_BLOCK_GLOBAL;
  1546.  
  1547.           /* Record where each reg is used, so when the reg
  1548.              is set we know the next insn that uses it.  */
  1549.  
  1550.           reg_next_use[regno] = insn;
  1551.  
  1552.           /* Count (weighted) number of uses of each reg.  */
  1553.  
  1554.           reg_n_refs[regno] += loop_depth;
  1555.         }
  1556.           /* Record and count the insns in which a reg dies.
  1557.          If it is used in this insn and was dead below the insn
  1558.          then it dies in this insn.  */
  1559.  
  1560.           if (!(needed[offset] & bit) && !is_needed
  1561.           && ! find_regno_note (insn, REG_DEAD, regno))
  1562.         {
  1563.           REG_NOTES (insn)
  1564.             = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (insn));
  1565.           reg_n_deaths[regno]++;
  1566.         }
  1567.         }
  1568.     }
  1569.       return;
  1570.  
  1571.     case SET:
  1572.       {
  1573.     register rtx testreg = SET_DEST (x);
  1574.     int mark_dest = 0;
  1575.  
  1576.     /* Storing in STRICT_LOW_PART is like storing in a reg
  1577.        in that this SET might be dead, so ignore it in TESTREG.
  1578.        but in some other ways it is like using the reg.  */
  1579.     /* Storing in a SUBREG or a bit field is like storing the entire
  1580.        register in that if the register's value is not used
  1581.        then this SET is not needed.  */
  1582.     while (GET_CODE (testreg) == STRICT_LOW_PART
  1583.            || GET_CODE (testreg) == ZERO_EXTRACT
  1584.            || GET_CODE (testreg) == SIGN_EXTRACT
  1585.            || GET_CODE (testreg) == SUBREG)
  1586.       {
  1587.         /* Modifying a single register in an alternate mode
  1588.            does not use any of the old value.  But these other
  1589.            ways of storing in a register do use the old value.  */
  1590.         if (GET_CODE (testreg) == SUBREG
  1591.         && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
  1592.           ;
  1593.         else
  1594.           mark_dest = 1;
  1595.  
  1596.         testreg = XEXP (testreg, 0);
  1597.       }
  1598.  
  1599.     /* If this is a store into a register,
  1600.        recursively scan the only value being stored,
  1601.        and only if the register's value is live after this insn.
  1602.        If the value being computed here would never be used
  1603.        then the values it uses don't need to be computed either.  */
  1604.  
  1605.     if (GET_CODE (testreg) == REG
  1606.         && (regno = REGNO (testreg), regno != FRAME_POINTER_REGNUM)
  1607.         && regno != ARG_POINTER_REGNUM)
  1608.       /*  && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
  1609.       {
  1610.         register int offset = regno / REGSET_ELT_BITS;
  1611.         register int bit = 1 << (regno % REGSET_ELT_BITS);
  1612.         if ((needed[offset] & bit)
  1613.         /* If insn refers to volatile, we mustn't delete it,
  1614.            so its inputs are all needed.  */
  1615.         || INSN_VOLATILE (insn))
  1616.           {
  1617.         mark_used_regs (needed, live, SET_SRC (x), final, insn);
  1618.         if (mark_dest)
  1619.           mark_used_regs (needed, live, SET_DEST (x), final, insn);
  1620.           }
  1621.         return;
  1622.       }
  1623.       }
  1624.       break;
  1625.     }
  1626.  
  1627.   /* Recursively scan the operands of this expression.  */
  1628.  
  1629.   {
  1630.     register char *fmt = GET_RTX_FORMAT (code);
  1631.     register int i;
  1632.     
  1633.     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1634.       {
  1635.     if (fmt[i] == 'e')
  1636.       {
  1637.         /* Tail recursive case: save a function call level.  */
  1638.         if (i == 0)
  1639.           {
  1640.         x = XEXP (x, 0);
  1641.         goto retry;
  1642.           }
  1643.         mark_used_regs (needed, live, XEXP (x, i), final, insn);
  1644.       }
  1645.     else if (fmt[i] == 'E')
  1646.       {
  1647.         register int j;
  1648.         for (j = 0; j < XVECLEN (x, i); j++)
  1649.           mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn);
  1650.       }
  1651.       }
  1652.   }
  1653. }
  1654.  
  1655. /* Nonzero if X contains any volatile memory references
  1656.    or volatile ASM_OPERANDS expressions.  */
  1657.  
  1658. static int
  1659. volatile_refs_p (x)
  1660.      rtx x;
  1661. {
  1662.   register RTX_CODE code;
  1663.  
  1664.   code = GET_CODE (x);
  1665.   switch (code)
  1666.     {
  1667.     case LABEL_REF:
  1668.     case SYMBOL_REF:
  1669.     case CONST_INT:
  1670.     case CONST:
  1671.     case CONST_DOUBLE:
  1672.     case CC0:
  1673.     case PC:
  1674.     case REG:
  1675.     case CLOBBER:
  1676.     case ASM_INPUT:
  1677.     case ADDR_VEC:
  1678.     case ADDR_DIFF_VEC:
  1679.       return 0;
  1680.  
  1681.     case CALL:
  1682.       return 1;
  1683.  
  1684.     case MEM:
  1685.     case ASM_OPERANDS:
  1686.       if (x->volatil)
  1687.     return 1;
  1688.     }
  1689.  
  1690.   /* Recursively scan the operands of this expression.  */
  1691.  
  1692.   {
  1693.     register char *fmt = GET_RTX_FORMAT (code);
  1694.     register int i;
  1695.     
  1696.     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1697.       {
  1698.     if (fmt[i] == 'e')
  1699.       {
  1700.         if (volatile_refs_p (XEXP (x, i)))
  1701.           return 1;
  1702.       }
  1703.     if (fmt[i] == 'E')
  1704.       {
  1705.         register int j;
  1706.         for (j = 0; j < XVECLEN (x, i); j++)
  1707.           if (volatile_refs_p (XVECEXP (x, i, j)))
  1708.         return 1;
  1709.       }
  1710.       }
  1711.   }
  1712.   return 0;
  1713. }
  1714.  
  1715. #ifdef AUTO_INC_DEC
  1716.  
  1717. static int
  1718. try_pre_increment_1 (insn)
  1719.      rtx insn;
  1720. {
  1721.   /* Find the next use of this reg.  If in same basic block,
  1722.      make it do pre-increment or pre-decrement if appropriate.  */
  1723.   rtx x = PATTERN (insn);
  1724.   int amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
  1725.         * INTVAL (XEXP (SET_SRC (x), 1)));
  1726.   int regno = REGNO (SET_DEST (x));
  1727.   rtx y = reg_next_use[regno];
  1728.   if (y != 0
  1729.       && BLOCK_NUM (y) == BLOCK_NUM (insn)
  1730.       && try_pre_increment (y, SET_DEST (PATTERN (insn)),
  1731.                 amount))
  1732.     {
  1733.       /* We have found a suitable auto-increment
  1734.      and already changed insn Y to do it.
  1735.      So flush this increment-instruction.  */
  1736.       PUT_CODE (insn, NOTE);
  1737.       NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1738.       NOTE_SOURCE_FILE (insn) = 0;
  1739.       /* Count a reference to this reg for the increment
  1740.      insn we are deleting.  When a reg is incremented.
  1741.      spilling it is worse, so we want to make that
  1742.      less likely.  */
  1743.       reg_n_refs[regno] += loop_depth;
  1744.       reg_n_sets[regno]++;
  1745.       return 1;
  1746.     }
  1747.   return 0;
  1748. }
  1749.  
  1750. /* Try to change INSN so that it does pre-increment or pre-decrement
  1751.    addressing on register REG in order to add AMOUNT to REG.
  1752.    AMOUNT is negative for pre-decrement.
  1753.    Returns 1 if the change could be made.
  1754.    This checks all about the validity of the result of modifying INSN.  */
  1755.  
  1756. static int
  1757. try_pre_increment (insn, reg, amount)
  1758.      rtx insn, reg;
  1759.      int amount;
  1760. {
  1761.   register rtx use;
  1762.  
  1763.   /* Nonzero if we can try to make a pre-increment or pre-decrement.
  1764.      For example, addl $4,r1; movl (r1),... can become movl +(r1),...  */
  1765.   int pre_ok = 0;
  1766.   /* Nonzero if we can try to make a post-increment or post-decrement.
  1767.      For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
  1768.      It is possible for both PRE_OK and POST_OK to be nonzero if the machine
  1769.      supports both pre-inc and post-inc, or both pre-dec and post-dec.  */
  1770.   int post_ok = 0;
  1771.  
  1772.   /* Nonzero if the opportunity actually requires post-inc or post-dec.  */
  1773.   int do_post = 0;
  1774.  
  1775.   /* From the sign of increment, see which possibilities are conceivable
  1776.      on this target machine.  */
  1777. #ifdef HAVE_PRE_INCREMENT
  1778.   if (amount > 0)
  1779.     pre_ok = 1;
  1780. #endif
  1781. #ifdef HAVE_POST_INCREMENT
  1782.   if (amount > 0)
  1783.     post_ok = 1;
  1784. #endif
  1785.  
  1786. #ifdef HAVE_PRE_DECREMENT
  1787.   if (amount < 0)
  1788.     pre_ok = 1;
  1789. #endif
  1790. #ifdef HAVE_POST_DECREMENT
  1791.   if (amount < 0)
  1792.     post_ok = 1;
  1793. #endif
  1794.  
  1795.   if (! (pre_ok || post_ok))
  1796.     return 0;
  1797.  
  1798.   /* It is not safe to add a side effect to a jump insn
  1799.      because if the incremented register is spilled and must be reloaded
  1800.      there would be no way to store the incremented value back in memory.  */
  1801.  
  1802.   if (GET_CODE (insn) == JUMP_INSN)
  1803.     return 0;
  1804.  
  1805.   use = 0;
  1806.   if (pre_ok)
  1807.     use = find_use_as_address (PATTERN (insn), reg, 0);
  1808.   if (post_ok && (use == 0 || use == (rtx) 1))
  1809.     {
  1810.       use = find_use_as_address (PATTERN (insn), reg, -amount);
  1811.       do_post = 1;
  1812.     }
  1813.  
  1814.   if (use == 0 || use == (rtx) 1)
  1815.     return 0;
  1816.  
  1817.   if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount))
  1818.     return 0;
  1819.  
  1820.   XEXP (use, 0) = gen_rtx (amount > 0
  1821.                ? (do_post ? POST_INC : PRE_INC)
  1822.                : (do_post ? POST_DEC : PRE_DEC),
  1823.                Pmode, reg);
  1824.  
  1825.   /* Record that this insn now has an implicit side effect on X.  */
  1826.   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, reg, REG_NOTES (insn));
  1827.   return 1;
  1828. }
  1829.  
  1830. #endif /* AUTO_INC_DEC */
  1831.  
  1832. /* Find the place in the rtx X where REG is used as a memory address.
  1833.    Return the MEM rtx that so uses it.
  1834.    If PLUSCONST is nonzero, search instead for a memory address equivalent to
  1835.    (plus REG (const_int PLUSCONST)).
  1836.  
  1837.    If such an address does not appear, return 0.
  1838.    If REG appears more than once, or is used other than in such an address,
  1839.    return (rtx)1.  */
  1840.  
  1841. static rtx
  1842. find_use_as_address (x, reg, plusconst)
  1843.      register rtx x;
  1844.      rtx reg;
  1845.      int plusconst;
  1846. {
  1847.   enum rtx_code code = GET_CODE (x);
  1848.   char *fmt = GET_RTX_FORMAT (code);
  1849.   register int i;
  1850.   register rtx value = 0;
  1851.   register rtx tem;
  1852.  
  1853.   if (code == MEM && XEXP (x, 0) == reg && plusconst == 0)
  1854.     return x;
  1855.  
  1856.   if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS
  1857.       && XEXP (XEXP (x, 0), 0) == reg
  1858.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  1859.       && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst)
  1860.     return x;
  1861.  
  1862.   if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
  1863.     {
  1864.       /* If REG occurs inside a MEM used in a bit-field reference,
  1865.      that is unacceptable.  */
  1866.       if (find_use_as_address (XEXP (x, 0), reg, 0) != 0)
  1867.     return (rtx) 1;
  1868.     }
  1869.  
  1870.   if (x == reg)
  1871.     return (rtx) 1;
  1872.  
  1873.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1874.     {
  1875.       if (fmt[i] == 'e')
  1876.     {
  1877.       tem = find_use_as_address (XEXP (x, i), reg, plusconst);
  1878.       if (value == 0)
  1879.         value = tem;
  1880.       else if (tem != 0)
  1881.         return (rtx) 1;
  1882.     }
  1883.       if (fmt[i] == 'E')
  1884.     {
  1885.       register int j;
  1886.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1887.         {
  1888.           tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst);
  1889.           if (value == 0)
  1890.         value = tem;
  1891.           else if (tem != 0)
  1892.         return (rtx) 1;
  1893.         }
  1894.     }
  1895.     }
  1896.  
  1897.   return value;
  1898. }
  1899.  
  1900. /* Write information about registers and basic blocks into FILE.
  1901.    This is part of making a debugging dump.  */
  1902.  
  1903. void
  1904. dump_flow_info (file)
  1905.      FILE *file;
  1906. {
  1907.   register int i;
  1908.   static char *reg_class_names[] = REG_CLASS_NAMES;
  1909.  
  1910.   fprintf (file, "%d registers.\n", max_regno);
  1911.  
  1912.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1913.     if (reg_n_refs[i])
  1914.       {
  1915.     enum reg_class class;
  1916.     fprintf (file, "\nRegister %d used %d times across %d insns",
  1917.          i, reg_n_refs[i], reg_live_length[i]);
  1918.     if (reg_basic_block[i] >= 0)
  1919.       fprintf (file, " in block %d", reg_basic_block[i]);
  1920.     if (reg_n_deaths[i] != 1)
  1921.       fprintf (file, "; dies in %d places", reg_n_deaths[i]);
  1922.     if (reg_crosses_call[i])
  1923.       fprintf (file, "; crosses calls");
  1924.     if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
  1925.       fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
  1926.     class = reg_preferred_class (i);
  1927.     if (class != GENERAL_REGS)
  1928.       {
  1929.         if (reg_preferred_or_nothing (i))
  1930.           fprintf (file, "; %s or none", reg_class_names[(int) class]);
  1931.         else
  1932.           fprintf (file, "; pref %s", reg_class_names[(int) class]);
  1933.       }
  1934.     if (REGNO_POINTER_FLAG (i))
  1935.       fprintf (file, "; pointer");
  1936.     fprintf (file, ".\n");
  1937.       }
  1938.   fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
  1939.   for (i = 0; i < n_basic_blocks; i++)
  1940.     {
  1941.       register rtx head, jump;
  1942.       register int regno;
  1943.       fprintf (file, "\nBasic block %d: first insn %d, last %d.\n",
  1944.            i,
  1945.            INSN_UID (basic_block_head[i]),
  1946.            INSN_UID (basic_block_end[i]));
  1947.       /* The control flow graph's storage is freed
  1948.      now when flow_analysis returns.
  1949.      Don't try to print it if it is gone.  */
  1950.       if (basic_block_drops_in)
  1951.     {
  1952.       fprintf (file, "Reached from blocks: ");
  1953.       head = basic_block_head[i];
  1954.       if (GET_CODE (head) == CODE_LABEL)
  1955.         for (jump = LABEL_REFS (head);
  1956.          jump != head;
  1957.          jump = LABEL_NEXTREF (jump))
  1958.           {
  1959.         register from_block = BLOCK_NUM (CONTAINING_INSN (jump));
  1960.         fprintf (file, " %d", from_block);
  1961.           }
  1962.       if (basic_block_drops_in[i])
  1963.         fprintf (file, " previous");
  1964.     }
  1965.       fprintf (file, "\nRegisters live at start:");
  1966.       for (regno = 0; regno < max_regno; regno++)
  1967.     {
  1968.       register int offset = regno / REGSET_ELT_BITS;
  1969.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1970.       if (basic_block_live_at_start[i][offset] & bit)
  1971.           fprintf (file, " %d", regno);
  1972.     }
  1973.       fprintf (file, "\n");
  1974.     }
  1975.   fprintf (file, "\n");
  1976. }
  1977.